package com.chatcompetition.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chatcompetition.common.api.CommonPage;
import com.chatcompetition.domain.entity.CompetitionActivity;
import com.chatcompetition.service.CompetitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/competition")
public class CompetitionController {

    @Autowired
    private CompetitionService competitionService;
    //打印全部的信息（超级管理员的权限）

    // 查询所有竞赛
    @GetMapping("/competitions")
    public List<CompetitionActivity> listAllCompetitions() {
        return competitionService.listAllCompetitions();
    }

    // 添加人老师查询自己添加的所有竞赛
    @GetMapping("/competitionsAddTeachers")
    public List<CompetitionActivity> listAllCompetitionsAddTeachers() {
        return competitionService.listAllCompetitionsAddTeachers();
    }

    // 添加人老师查询自己添加的所有竞赛分页
    // 添加人老师查询自己添加的所有竞赛（分页）
    @GetMapping("/competitionsAddTeachersPage")
    public CommonPage<CompetitionActivity> listAllCompetitionsAddTeachers(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return competitionService.listAllCompetitionsAddTeachersPage(page, size);
    }

    @GetMapping("/competitionsPage")
    public CommonPage<CompetitionActivity> listAllCompetitions(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return competitionService.listAllCompetitionsPage(page, size);
    }




    /**
     * 根据类别和种类查询竞赛活动
     */
    @GetMapping("/competitions-filter")
    public List<CompetitionActivity> getCompetitions(
            @RequestParam(required = false) String category,
            @RequestParam(required = false) String sub_category) {
        return competitionService.getCompetitionsByFilters(category, sub_category);
    }
    @GetMapping("/{id}")
    public CompetitionActivity getById(@PathVariable Long id) {
        return competitionService.getById(id);
    }

    @PostMapping("/save")
    public boolean save(@RequestBody CompetitionActivity activity) {
        return competitionService.save(activity);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody CompetitionActivity activity) {
        return competitionService.update(activity);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return competitionService.delete(id);
    }

    @GetMapping("/sub-categories")
    public List<String> getSubCategoriesByCategory(@RequestParam String category) {
        return competitionService.getSubCategoriesByCategory(category);
    }
}